package com.hgw.easyrocketmq.delay.producer;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

/**
 * Description: 延迟消息demo
 *
 * @author LinHuiBa-YanAn
 * @date 2023/1/15 14:59
 */
public class ScheduledMessageProducer {

	public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
		DefaultMQProducer mqProducer = new DefaultMQProducer("group1");
		mqProducer.setNamesrvAddr("124.222.223.222:9876;47.96.232.192:9876");
		mqProducer.start();
		for (int i = 0; i < 10; i++) {
			Message msg = new Message("delayTopic", "DEALY", ("Hello,延迟队列" + i).getBytes());
			// 设置延时等级，消息将在等级对应的事件后发送（如等级3，这个消息将在10s之后发送。想看）
			msg.setDelayTimeLevel(3);
			mqProducer.send(msg);
		}
		mqProducer.shutdown();
	}

}
